package com.wzcl.app.dao.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.wzcl.app.dao.model.common.Base;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Getter
@Setter
@Entity
@Table(name = "Activity",
        indexes = {
                @Index(columnList = "type"),
                @Index(columnList = "activityState")
        }
)
@ApiModel(value = "活动表")
@EntityListeners(AuditingEntityListener.class)
public class Activity implements Base {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ApiModelProperty(value = "类型名称")
    private String name;

    @ApiModelProperty(value = "活动类型(对应子活动类型)")
    private Integer type;

    @ApiModelProperty(value = "活动作用范围")
    private Integer scope;

    @CreatedDate
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @LastModifiedDate
    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    @ApiModelProperty(value = "活动地址")
    private String activityUrl;

    @ApiModelProperty(value = "活动状态")
    private Integer activityState;

    @ApiModelProperty(value = "排序字段")
    private Integer orderNo;

    @JsonIgnoreProperties(value = {"activityList"})
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "commodityAndActivity",
            joinColumns = {@JoinColumn(name = "activityId", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "commodityId", referencedColumnName = "id")})
    private List<Commodity> commodityList;
}
